<template>
  <div v-if="showCameraInfo && selectedCamera" class="camera-info-box">
    <div class="info-header">
      <h3>{{ selectedCamera.name }}</h3>
      <button @click="$emit('close')" class="close-btn">×</button>
    </div>
    <div class="info-content">
      <div class="info-row">
        <span class="label">状态:</span>
        <span class="value" :class="selectedCamera.status">
          {{ getStatusText(selectedCamera.status) }}
        </span>
      </div>
      <div class="info-row">
        <span class="label">位置:</span>
        <span class="value">{{ selectedCamera.location || '未设置' }}</span>
      </div>
      <div class="info-row">
        <span class="label">设备ID:</span>
        <span class="value">{{ selectedCamera.wvp_device_id || selectedCamera.id }}</span>
      </div>
      <div class="info-row">
        <span class="label">坐标:</span>
        <span class="value">{{ formatPosition(selectedCamera.position) }}</span>
      </div>
      <div class="info-actions">
        <button @click="$emit('flyToCamera', selectedCamera)" class="action-btn focus-btn">
          聚焦
        </button>
        <button 
          v-if="selectedCamera.status === 'online'" 
          @click="$emit('openVideoPlayer', selectedCamera)" 
          class="action-btn play-btn"
        >
          播放视频
        </button>
        <button 
          v-else 
          disabled 
          class="action-btn disabled-btn"
        >
          设备离线
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
// 定义props
const props = defineProps({
  showCameraInfo: Boolean,
  selectedCamera: Object
})

// 定义事件
defineEmits(['close', 'flyToCamera', 'openVideoPlayer'])

// 工具函数
const getStatusText = (status) => {
  switch (status) {
    case 'online': return '在线'
    case 'offline': return '离线'
    case 'maintenance': return '维护中'
    default: return '未知'
  }
}

const formatPosition = (position) => {
  if (!position) return '未设置'
  return `(${(position.lng && position.lng.toFixed(6)) || 0}, ${(position.lat && position.lat.toFixed(6)) || 0}, ${(position.height && position.height.toFixed(1)) || 0}m)`
}
</script>

<style lang="scss" scoped>
.camera-info-box {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 320px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 2000;
  border: 1px solid #e1e5e9;

  .info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;

    h3 {
      margin: 0;
      font-size: 16px;
      font-weight: 600;
      color: #1f2937;
    }

    .close-btn {
      background: none;
      border: none;
      font-size: 20px;
      cursor: pointer;
      color: #6c757d;
      padding: 4px;
      border-radius: 4px;
      
      &:hover {
        background: #e9ecef;
        color: #495057;
      }
    }
  }

  .info-content {
    padding: 16px 20px;
  }

  .info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;

    .label {
      font-weight: 600;
      color: #495057;
      min-width: 60px;
    }

    .value {
      color: #6c757d;
      text-align: right;
      flex: 1;
      margin-left: 12px;
      
      &.online {
        color: #28a745;
        font-weight: 600;
      }
      
      &.offline {
        color: #dc3545;
        font-weight: 600;
      }
      
      &.maintenance {
        color: #ffc107;
        font-weight: 600;
      }
    }
  }

  .info-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;

    .action-btn {
      flex: 1;
      padding: 8px 16px;
      border: none;
      border-radius: 6px;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s;

      &.focus-btn {
        background: #409eff;
        color: white;
        
        &:hover {
          background: #66b1ff;
        }
      }

      &.play-btn {
        background: #67c23a;
        color: white;
        
        &:hover {
          background: #85ce61;
        }
      }

      &.disabled-btn {
        background: #f5f5f5;
        color: #999;
        cursor: not-allowed;
      }
    }
  }
}
</style>